import cn.lhl.entity.Dept;
import cn.lhl.entity.Emp;
import org.hibernate.Query;
import org.hibernate.Session;

import java.util.Iterator;
import java.util.List;

/**
 * Created by datou on 2017/1/21.
 */
public class test {
    public static void main(String[] args) {
//        Session session=HibernateUtil.getSession();
//        Query query = session.createQuery("from  Dept");
////        List<Dept> list = query.list();
////        for (Dept item:list) {
////            System.out.println(item.getDname());
////        }
////        list=query.list();
////        for (Dept item:list) {
////            System.out.println(item.getDname());
////        }
////        Iterator<Dept> iterate = query.iterate();
////        while (iterate.hasNext()){
////            System.out.println(iterate.next().getDname());
////        }
//        session.close();
//        Session session=HibernateUtil.getSession();
//        Dept dept=session.get(Dept.class,1);
//       HibernateUtil.close();
//        Session session2=HibernateUtil.getSession();
//        Dept dept2=session2.get(Dept.class,1);
//        HibernateUtil.close();
//        Session session=HibernateUtil.getSession();
//        Emp emp=new Emp();
//        emp.setEname("小王");
//        Emp emp1=new Emp();
//        emp1.setEname("小刘");
//        Dept dept=new Dept();
//        dept.setDname("文化步");
//        dept.setAge("18");
//        dept.getEmps().add(emp);
//        dept.getEmps().add(emp1);
//        session.save(dept);
//        HibernateUtil.close();
        Session session=HibernateUtil.getSession();
        Query query = session.createQuery("from Dept ").setCacheable(true);
        List<Dept> list=query.list();

        HibernateUtil.close();
        System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
        Session session1=HibernateUtil.getSession();
        Query query1 = session1.createQuery("from Dept ").setCacheable(true);
        List<Dept> list1=query1.list();
        HibernateUtil.close();
    }
}
